<?php
class JBSControllerAssets extends JController {
	function __construct() {
		parent :: __construct();

		// Register Extra tasks
		$this->registerTask('add', 'edit');
	}

	function display()
	{
		if (!JBSRoles :: checkPermission($this, JBSConfig :: $VIEW_ASSETS, 'index.php?option=com_jbschedule', JText :: _('View Assets').' - '.JText :: _('NO PERMISSION')))
			return;

		JRequest :: setVar('view', 'assets');
		JRequest :: setVar('layout', 'list');
		parent::display();
	}

	/**
	 * display the edit form
	 * @return void
	 */
	function edit() {
		if ($this->getTask() === 'add') {
			if (!JBSRoles :: checkPermission($this, JBSConfig :: $ADD_ASSETS, 'index.php?option=com_jbschedule&controller=assets', JText :: _('Add new Assets').' - '.JText :: _('NO PERMISSION')))
				return;
		}
		else if ($this->getTask() === 'edit') {
			if (!JBSRoles :: checkPermission($this, JBSConfig :: $EDIT_ASSETS, 'index.php?option=com_jbschedule&controller=assets', JText :: _('Edit Assets').' - '.JText :: _('NO PERMISSION')))
				return;
		}

		JRequest :: setVar('view', 'assets');
		JRequest :: setVar('layout', 'form');
//		JRequest :: setVar('hidemainmenu', 1);

		//Lay ve AssetGroups Model
		$model = $this->getModel('assetgroups');
		//Lay ve All Groups
		$assetgroups = $model->getAllData();
		//Dua vao Request de chuyen toi View class
		JRequest :: setVar('assetgroups', $assetgroups);

		parent :: display();
	}

	/**
	 * save a record (and redirect to main page)
	 * @return void
	 */
	function save() {
		$model = $this->getModel('assets');

		if ($model->store($post)) {
			$msg = JText :: _('SAVED');
			$link = 'index.php?option=com_jbschedule&controller=assets';
			$this->setRedirect($link, $msg);
		} else {
			$msg = JText :: _('NOT SAVED');
			$link = 'index.php?option=com_jbschedule&controller=assets';
			$this->setRedirect($link, $msg);
		}
	}

	/**
	 * remove record(s)
	 * @return void
	 */
	function remove() {
		if (!JBSRoles :: checkPermission($this, JBSConfig :: $DEL_ASSETS, 'index.php?option=com_jbschedule&controller=assets', JText :: _('Delete Assets').' - '.JText :: _('NO PERMISSION')))
			return;

		$model = $this->getModel('assets');
		if (!$model->delete()) {
			$msg = JText :: _('NOT DELETED');
		} else {
			$msg = JText :: _('DELETED');
		}

		$this->setRedirect('index.php?option=com_jbschedule&controller=assets', $msg);
	}

	/**
	 * cancel editing a record
	 * @return void
	 */
	function cancel() {
		$msg = JText :: _('CANCELED');
		$this->setRedirect('index.php?option=com_jbschedule&controller=assets', $msg);
	}
	function showGroup(){
		if (!JBSRoles :: checkPermission($this, JBSConfig :: $DEL_ASSETS, 'index.php?option=com_jbschedule&controller=assets', JText :: _('Show Group').' - '.JText :: _('NO PERMISSION')))
			return;
		JRequest :: setVar('view', 'assets');
		JRequest :: setVar('layout', 'testshow');
		parent::display();
	}
}
?>
